package com.chengjue.service.impl;

import com.chengjue.service.RequireService;
import com.chengjue.common.ServerResponse;
import com.chengjue.dao.RequireModelMapper;
import com.chengjue.model.RequireModel;
import com.chengjue.movie.GetMovieRunnable;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class RequireServiceImpl implements RequireService {
    @Autowired
    RequireModelMapper requireModelMapper;

    ExecutorService threadPool = Executors.newCachedThreadPool();
    @Override
    public ServerResponse<String> getData(Long id) {
        //批量抓取数据 存储到数据库
        threadPool.execute(new GetMovieRunnable(requireModelMapper,id));
        return ServerResponse.createBySuccessMessage("正在抓取数据");
    }

    @Override
    public ServerResponse<PageInfo> getList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<RequireModel> list = requireModelMapper.selectRequire();
        PageInfo pageInfo = new PageInfo(list);
        return ServerResponse.createBySuccess(pageInfo);
    }
}
